{
 "cells": [
  {
   "cell_type": "code",
   "execution_count": 1,
   "id": "golden-lover",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/html": [
       "   <div id=\"bLsWDr\"></div>\n",
       "   <script type=\"text/javascript\" data-lets-plot-script=\"library\">\n",
       "       if(!window.letsPlotCallQueue) {\n",
       "           window.letsPlotCallQueue = [];\n",
       "       }; \n",
       "       window.letsPlotCall = function(f) {\n",
       "           window.letsPlotCallQueue.push(f);\n",
       "       };\n",
       "       (function() {\n",
       "           var script = document.createElement(\"script\");\n",
       "           script.type = \"text/javascript\";\n",
       "           script.src = \"https://cdn.jsdelivr.net/gh/JetBrains/lets-plot@v2.5.1/js-package/distr/lets-plot.min.js\";\n",
       "           script.onload = function() {\n",
       "               window.letsPlotCall = function(f) {f();};\n",
       "               window.letsPlotCallQueue.forEach(function(f) {f();});\n",
       "               window.letsPlotCallQueue = [];\n",
       "               \n",
       "               \n",
       "           };\n",
       "           script.onerror = function(event) {\n",
       "               window.letsPlotCall = function(f) {};\n",
       "               window.letsPlotCallQueue = [];\n",
       "               var div = document.createElement(\"div\");\n",
       "               div.style.color = 'darkred';\n",
       "               div.textContent = 'Error loading Lets-Plot JS';\n",
       "               document.getElementById(\"bLsWDr\").appendChild(div);\n",
       "           };\n",
       "           var e = document.getElementById(\"bLsWDr\");\n",
       "           e.appendChild(script);\n",
       "       })();\n",
       "   </script>"
      ]
     },
     "metadata": {},
     "output_type": "display_data"
    }
   ],
   "source": [
    "%useLatestDescriptors\n",
    "%use lets-plot"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 2,
   "id": "increasing-garage",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "Lets-Plot Kotlin API v.4.1.1. Frontend: Notebook with dynamically loaded JS. Lets-Plot JS v.2.5.1."
      ]
     },
     "execution_count": 2,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "LetsPlot.getInfo()"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 3,
   "id": "happy-source",
   "metadata": {},
   "outputs": [],
   "source": [
    "// Support of multiple lines\n",
    "\n",
    "\n",
    "val justifications = listOf(0, 0.5, 1)\n",
    "val angles = listOf(0, 30)\n",
    "\n",
    "val values = justifications.flatMap { hjust ->\n",
    "    justifications.flatMap { vjust ->\n",
    "        angles.map { angle ->\n",
    "            Triple(hjust, vjust, angle)\n",
    "        }\n",
    "    }\n",
    "}\n",
    "\n",
    "val data = mapOf(\n",
    "    \"hjust\" to values.map { it.first },\n",
    "    \"vjust\" to values.map { it.second },\n",
    "    \"angle\" to values.map { it.third },\n",
    "    \"label\" to values.map { \"first line\\nsecond line\" },\n",
    ")\n",
    "\n",
    "\n",
    "val p = letsPlot(data) { x = \"hjust\"; y = \"vjust\" } +\n",
    "        geomPoint(size = 3) +\n",
    "        themeLight() + theme(panelGrid=elementBlank())\n",
    "\n",
    "val pf = (p + scaleXContinuous(breaks = listOf(0, 0.5, 1)) +\n",
    "    scaleYContinuous(breaks = listOf(0, 0.5, 1), expand = listOf(0.4)) +\n",
    "    facetGrid(x = \"angle\", xFormat = \"{d}°\"))"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 4,
   "id": "ceramic-understanding",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/html": [
       "   <div id=\"1llLXQ\"></div>\n",
       "   <script type=\"text/javascript\" data-lets-plot-script=\"plot\">\n",
       "       (function() {\n",
       "           var plotSpec={\n",
       "\"mapping\":{\n",
       "\"x\":\"hjust\",\n",
       "\"y\":\"vjust\"\n",
       "},\n",
       "\"data\":{\n",
       "\"vjust\":[0.0,0.0,0.5,0.5,1.0,1.0,0.0,0.0,0.5,0.5,1.0,1.0,0.0,0.0,0.5,0.5,1.0,1.0],\n",
       "\"angle\":[0.0,30.0,0.0,30.0,0.0,30.0,0.0,30.0,0.0,30.0,0.0,30.0,0.0,30.0,0.0,30.0,0.0,30.0],\n",
       "\"label\":[\"first line\\nsecond line\",\"first line\\nsecond line\",\"first line\\nsecond line\",\"first line\\nsecond line\",\"first line\\nsecond line\",\"first line\\nsecond line\",\"first line\\nsecond line\",\"first line\\nsecond line\",\"first line\\nsecond line\",\"first line\\nsecond line\",\"first line\\nsecond line\",\"first line\\nsecond line\",\"first line\\nsecond line\",\"first line\\nsecond line\",\"first line\\nsecond line\",\"first line\\nsecond line\",\"first line\\nsecond line\",\"first line\\nsecond line\"],\n",
       "\"hjust\":[0.0,0.0,0.0,0.0,0.0,0.0,0.5,0.5,0.5,0.5,0.5,0.5,1.0,1.0,1.0,1.0,1.0,1.0]\n",
       "},\n",
       "\"kind\":\"plot\",\n",
       "\"scales\":[{\n",
       "\"aesthetic\":\"x\",\n",
       "\"breaks\":[0.0,0.5,1.0]\n",
       "},{\n",
       "\"aesthetic\":\"y\",\n",
       "\"expand\":[0.4],\n",
       "\"breaks\":[0.0,0.5,1.0]\n",
       "}],\n",
       "\"layers\":[{\n",
       "\"mapping\":{\n",
       "},\n",
       "\"stat\":\"identity\",\n",
       "\"size\":3.0,\n",
       "\"position\":\"identity\",\n",
       "\"geom\":\"point\",\n",
       "\"data\":{\n",
       "}\n",
       "},{\n",
       "\"mapping\":{\n",
       "\"label\":\"label\",\n",
       "\"hjust\":\"hjust\",\n",
       "\"vjust\":\"vjust\",\n",
       "\"angle\":\"angle\"\n",
       "},\n",
       "\"stat\":\"identity\",\n",
       "\"size\":9.0,\n",
       "\"position\":\"identity\",\n",
       "\"geom\":\"text\",\n",
       "\"data\":{\n",
       "}\n",
       "}],\n",
       "\"theme\":{\n",
       "\"name\":\"light\",\n",
       "\"panel_grid\":{\n",
       "\"blank\":true\n",
       "}\n",
       "},\n",
       "\"facet\":{\n",
       "\"name\":\"grid\",\n",
       "\"x\":\"angle\",\n",
       "\"x_format\":\"{d}°\",\n",
       "\"x_order\":1.0,\n",
       "\"y_order\":1.0\n",
       "}\n",
       "};\n",
       "           var plotContainer = document.getElementById(\"1llLXQ\");\n",
       "           window.letsPlotCall(function() {{\n",
       "               LetsPlot.buildPlotFromProcessedSpecs(plotSpec, -1, -1, plotContainer);\n",
       "           }});\n",
       "       })();    \n",
       "   </script>"
      ]
     },
     "execution_count": 4,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "pf + geomText(size = 9) { label = \"label\"; hjust = \"hjust\"; vjust = \"vjust\"; angle = \"angle\" }"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 5,
   "id": "crude-immigration",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/html": [
       "   <div id=\"Vre2Lo\"></div>\n",
       "   <script type=\"text/javascript\" data-lets-plot-script=\"plot\">\n",
       "       (function() {\n",
       "           var plotSpec={\n",
       "\"mapping\":{\n",
       "\"x\":\"hjust\",\n",
       "\"y\":\"vjust\"\n",
       "},\n",
       "\"data\":{\n",
       "\"vjust\":[0.0,0.0,0.5,0.5,1.0,1.0,0.0,0.0,0.5,0.5,1.0,1.0,0.0,0.0,0.5,0.5,1.0,1.0],\n",
       "\"angle\":[0.0,30.0,0.0,30.0,0.0,30.0,0.0,30.0,0.0,30.0,0.0,30.0,0.0,30.0,0.0,30.0,0.0,30.0],\n",
       "\"label\":[\"first line\\nsecond line\",\"first line\\nsecond line\",\"first line\\nsecond line\",\"first line\\nsecond line\",\"first line\\nsecond line\",\"first line\\nsecond line\",\"first line\\nsecond line\",\"first line\\nsecond line\",\"first line\\nsecond line\",\"first line\\nsecond line\",\"first line\\nsecond line\",\"first line\\nsecond line\",\"first line\\nsecond line\",\"first line\\nsecond line\",\"first line\\nsecond line\",\"first line\\nsecond line\",\"first line\\nsecond line\",\"first line\\nsecond line\"],\n",
       "\"hjust\":[0.0,0.0,0.0,0.0,0.0,0.0,0.5,0.5,0.5,0.5,0.5,0.5,1.0,1.0,1.0,1.0,1.0,1.0]\n",
       "},\n",
       "\"kind\":\"plot\",\n",
       "\"scales\":[{\n",
       "\"aesthetic\":\"x\",\n",
       "\"breaks\":[0.0,0.5,1.0]\n",
       "},{\n",
       "\"aesthetic\":\"y\",\n",
       "\"expand\":[0.4],\n",
       "\"breaks\":[0.0,0.5,1.0]\n",
       "}],\n",
       "\"layers\":[{\n",
       "\"mapping\":{\n",
       "},\n",
       "\"stat\":\"identity\",\n",
       "\"size\":3.0,\n",
       "\"position\":\"identity\",\n",
       "\"geom\":\"point\",\n",
       "\"data\":{\n",
       "}\n",
       "},{\n",
       "\"mapping\":{\n",
       "\"label\":\"label\",\n",
       "\"hjust\":\"hjust\",\n",
       "\"vjust\":\"vjust\",\n",
       "\"angle\":\"angle\"\n",
       "},\n",
       "\"stat\":\"identity\",\n",
       "\"size\":9.0,\n",
       "\"alpha\":0.5,\n",
       "\"position\":\"identity\",\n",
       "\"geom\":\"label\",\n",
       "\"data\":{\n",
       "}\n",
       "}],\n",
       "\"theme\":{\n",
       "\"name\":\"light\",\n",
       "\"panel_grid\":{\n",
       "\"blank\":true\n",
       "}\n",
       "},\n",
       "\"facet\":{\n",
       "\"name\":\"grid\",\n",
       "\"x\":\"angle\",\n",
       "\"x_format\":\"{d}°\",\n",
       "\"x_order\":1.0,\n",
       "\"y_order\":1.0\n",
       "}\n",
       "};\n",
       "           var plotContainer = document.getElementById(\"Vre2Lo\");\n",
       "           window.letsPlotCall(function() {{\n",
       "               LetsPlot.buildPlotFromProcessedSpecs(plotSpec, -1, -1, plotContainer);\n",
       "           }});\n",
       "       })();    \n",
       "   </script>"
      ]
     },
     "execution_count": 5,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "pf + geomLabel(size = 9, alpha = 0.5) { label = \"label\"; hjust = \"hjust\"; vjust = \"vjust\"; angle = \"angle\" }"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 6,
   "id": "funky-dubai",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/html": [
       "   <div id=\"vVf5D2\"></div>\n",
       "   <script type=\"text/javascript\" data-lets-plot-script=\"plot\">\n",
       "       (function() {\n",
       "           var plotSpec={\n",
       "\"mapping\":{\n",
       "\"x\":\"hjust\",\n",
       "\"y\":\"vjust\"\n",
       "},\n",
       "\"data\":{\n",
       "\"vjust\":[0.0,0.0,0.5,0.5,1.0,1.0,0.0,0.0,0.5,0.5,1.0,1.0,0.0,0.0,0.5,0.5,1.0,1.0],\n",
       "\"label\":[\"first line\\nsecond line\",\"first line\\nsecond line\",\"first line\\nsecond line\",\"first line\\nsecond line\",\"first line\\nsecond line\",\"first line\\nsecond line\",\"first line\\nsecond line\",\"first line\\nsecond line\",\"first line\\nsecond line\",\"first line\\nsecond line\",\"first line\\nsecond line\",\"first line\\nsecond line\",\"first line\\nsecond line\",\"first line\\nsecond line\",\"first line\\nsecond line\",\"first line\\nsecond line\",\"first line\\nsecond line\",\"first line\\nsecond line\"],\n",
       "\"hjust\":[0.0,0.0,0.0,0.0,0.0,0.0,0.5,0.5,0.5,0.5,0.5,0.5,1.0,1.0,1.0,1.0,1.0,1.0]\n",
       "},\n",
       "\"kind\":\"plot\",\n",
       "\"scales\":[],\n",
       "\"layers\":[{\n",
       "\"mapping\":{\n",
       "},\n",
       "\"stat\":\"identity\",\n",
       "\"size\":3.0,\n",
       "\"position\":\"identity\",\n",
       "\"geom\":\"point\",\n",
       "\"data\":{\n",
       "}\n",
       "},{\n",
       "\"mapping\":{\n",
       "\"label\":\"label\",\n",
       "\"hjust\":\"hjust\",\n",
       "\"vjust\":\"vjust\"\n",
       "},\n",
       "\"stat\":\"identity\",\n",
       "\"size\":9.0,\n",
       "\"lineheight\":0.7,\n",
       "\"position\":\"identity\",\n",
       "\"geom\":\"text\",\n",
       "\"data\":{\n",
       "}\n",
       "}],\n",
       "\"theme\":{\n",
       "\"name\":\"light\",\n",
       "\"panel_grid\":{\n",
       "\"blank\":true\n",
       "}\n",
       "}\n",
       "};\n",
       "           var plotContainer = document.getElementById(\"vVf5D2\");\n",
       "           window.letsPlotCall(function() {{\n",
       "               LetsPlot.buildPlotFromProcessedSpecs(plotSpec, -1, -1, plotContainer);\n",
       "           }});\n",
       "       })();    \n",
       "   </script>"
      ]
     },
     "execution_count": 6,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "// Change lineheight\n",
    "\n",
    "// lineheight = 0.7\n",
    "\n",
    "p + geomText(size = 9, lineheight = 0.7) { label = \"label\"; hjust = \"hjust\"; vjust = \"vjust\" }"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 7,
   "id": "frozen-broadcasting",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/html": [
       "   <div id=\"uv3vMj\"></div>\n",
       "   <script type=\"text/javascript\" data-lets-plot-script=\"plot\">\n",
       "       (function() {\n",
       "           var plotSpec={\n",
       "\"mapping\":{\n",
       "\"x\":\"hjust\",\n",
       "\"y\":\"vjust\"\n",
       "},\n",
       "\"data\":{\n",
       "\"vjust\":[0.0,0.0,0.5,0.5,1.0,1.0,0.0,0.0,0.5,0.5,1.0,1.0,0.0,0.0,0.5,0.5,1.0,1.0],\n",
       "\"label\":[\"first line\\nsecond line\",\"first line\\nsecond line\",\"first line\\nsecond line\",\"first line\\nsecond line\",\"first line\\nsecond line\",\"first line\\nsecond line\",\"first line\\nsecond line\",\"first line\\nsecond line\",\"first line\\nsecond line\",\"first line\\nsecond line\",\"first line\\nsecond line\",\"first line\\nsecond line\",\"first line\\nsecond line\",\"first line\\nsecond line\",\"first line\\nsecond line\",\"first line\\nsecond line\",\"first line\\nsecond line\",\"first line\\nsecond line\"],\n",
       "\"hjust\":[0.0,0.0,0.0,0.0,0.0,0.0,0.5,0.5,0.5,0.5,0.5,0.5,1.0,1.0,1.0,1.0,1.0,1.0]\n",
       "},\n",
       "\"kind\":\"plot\",\n",
       "\"scales\":[],\n",
       "\"layers\":[{\n",
       "\"mapping\":{\n",
       "},\n",
       "\"stat\":\"identity\",\n",
       "\"size\":3.0,\n",
       "\"position\":\"identity\",\n",
       "\"geom\":\"point\",\n",
       "\"data\":{\n",
       "}\n",
       "},{\n",
       "\"mapping\":{\n",
       "\"label\":\"label\",\n",
       "\"hjust\":\"hjust\",\n",
       "\"vjust\":\"vjust\"\n",
       "},\n",
       "\"stat\":\"identity\",\n",
       "\"size\":9.0,\n",
       "\"alpha\":0.5,\n",
       "\"lineheight\":0.7,\n",
       "\"position\":\"identity\",\n",
       "\"geom\":\"label\",\n",
       "\"data\":{\n",
       "}\n",
       "}],\n",
       "\"theme\":{\n",
       "\"name\":\"light\",\n",
       "\"panel_grid\":{\n",
       "\"blank\":true\n",
       "}\n",
       "}\n",
       "};\n",
       "           var plotContainer = document.getElementById(\"uv3vMj\");\n",
       "           window.letsPlotCall(function() {{\n",
       "               LetsPlot.buildPlotFromProcessedSpecs(plotSpec, -1, -1, plotContainer);\n",
       "           }});\n",
       "       })();    \n",
       "   </script>"
      ]
     },
     "execution_count": 7,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "p + geomLabel(size = 9, alpha = 0.5, lineheight = 0.7) { label = \"label\"; hjust = \"hjust\"; vjust = \"vjust\" }"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 8,
   "id": "eight-turtle",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/html": [
       "   <div id=\"WxNW8b\"></div>\n",
       "   <script type=\"text/javascript\" data-lets-plot-script=\"plot\">\n",
       "       (function() {\n",
       "           var plotSpec={\n",
       "\"mapping\":{\n",
       "\"x\":\"hjust\",\n",
       "\"y\":\"vjust\"\n",
       "},\n",
       "\"data\":{\n",
       "\"vjust\":[0.0,0.0,0.5,0.5,1.0,1.0,0.0,0.0,0.5,0.5,1.0,1.0,0.0,0.0,0.5,0.5,1.0,1.0],\n",
       "\"label\":[\"first line\\nsecond line\",\"first line\\nsecond line\",\"first line\\nsecond line\",\"first line\\nsecond line\",\"first line\\nsecond line\",\"first line\\nsecond line\",\"first line\\nsecond line\",\"first line\\nsecond line\",\"first line\\nsecond line\",\"first line\\nsecond line\",\"first line\\nsecond line\",\"first line\\nsecond line\",\"first line\\nsecond line\",\"first line\\nsecond line\",\"first line\\nsecond line\",\"first line\\nsecond line\",\"first line\\nsecond line\",\"first line\\nsecond line\"],\n",
       "\"hjust\":[0.0,0.0,0.0,0.0,0.0,0.0,0.5,0.5,0.5,0.5,0.5,0.5,1.0,1.0,1.0,1.0,1.0,1.0]\n",
       "},\n",
       "\"kind\":\"plot\",\n",
       "\"scales\":[],\n",
       "\"layers\":[{\n",
       "\"mapping\":{\n",
       "},\n",
       "\"stat\":\"identity\",\n",
       "\"size\":3.0,\n",
       "\"position\":\"identity\",\n",
       "\"geom\":\"point\",\n",
       "\"data\":{\n",
       "}\n",
       "},{\n",
       "\"mapping\":{\n",
       "\"label\":\"label\",\n",
       "\"hjust\":\"hjust\",\n",
       "\"vjust\":\"vjust\"\n",
       "},\n",
       "\"stat\":\"identity\",\n",
       "\"size\":9.0,\n",
       "\"lineheight\":2.0,\n",
       "\"position\":\"identity\",\n",
       "\"geom\":\"text\",\n",
       "\"data\":{\n",
       "}\n",
       "}],\n",
       "\"theme\":{\n",
       "\"name\":\"light\",\n",
       "\"panel_grid\":{\n",
       "\"blank\":true\n",
       "}\n",
       "}\n",
       "};\n",
       "           var plotContainer = document.getElementById(\"WxNW8b\");\n",
       "           window.letsPlotCall(function() {{\n",
       "               LetsPlot.buildPlotFromProcessedSpecs(plotSpec, -1, -1, plotContainer);\n",
       "           }});\n",
       "       })();    \n",
       "   </script>"
      ]
     },
     "execution_count": 8,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "// lineheight = 2.0\n",
    "\n",
    "p + geomText(size = 9, lineheight = 2) { label = \"label\"; hjust = \"hjust\"; vjust = \"vjust\" }"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 9,
   "id": "meaningful-darkness",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/html": [
       "   <div id=\"97wlhC\"></div>\n",
       "   <script type=\"text/javascript\" data-lets-plot-script=\"plot\">\n",
       "       (function() {\n",
       "           var plotSpec={\n",
       "\"mapping\":{\n",
       "\"x\":\"hjust\",\n",
       "\"y\":\"vjust\"\n",
       "},\n",
       "\"data\":{\n",
       "\"vjust\":[0.0,0.0,0.5,0.5,1.0,1.0,0.0,0.0,0.5,0.5,1.0,1.0,0.0,0.0,0.5,0.5,1.0,1.0],\n",
       "\"label\":[\"first line\\nsecond line\",\"first line\\nsecond line\",\"first line\\nsecond line\",\"first line\\nsecond line\",\"first line\\nsecond line\",\"first line\\nsecond line\",\"first line\\nsecond line\",\"first line\\nsecond line\",\"first line\\nsecond line\",\"first line\\nsecond line\",\"first line\\nsecond line\",\"first line\\nsecond line\",\"first line\\nsecond line\",\"first line\\nsecond line\",\"first line\\nsecond line\",\"first line\\nsecond line\",\"first line\\nsecond line\",\"first line\\nsecond line\"],\n",
       "\"hjust\":[0.0,0.0,0.0,0.0,0.0,0.0,0.5,0.5,0.5,0.5,0.5,0.5,1.0,1.0,1.0,1.0,1.0,1.0]\n",
       "},\n",
       "\"kind\":\"plot\",\n",
       "\"scales\":[],\n",
       "\"layers\":[{\n",
       "\"mapping\":{\n",
       "},\n",
       "\"stat\":\"identity\",\n",
       "\"size\":3.0,\n",
       "\"position\":\"identity\",\n",
       "\"geom\":\"point\",\n",
       "\"data\":{\n",
       "}\n",
       "},{\n",
       "\"mapping\":{\n",
       "\"label\":\"label\",\n",
       "\"hjust\":\"hjust\",\n",
       "\"vjust\":\"vjust\"\n",
       "},\n",
       "\"stat\":\"identity\",\n",
       "\"size\":9.0,\n",
       "\"alpha\":0.5,\n",
       "\"lineheight\":2.0,\n",
       "\"position\":\"identity\",\n",
       "\"geom\":\"label\",\n",
       "\"data\":{\n",
       "}\n",
       "}],\n",
       "\"theme\":{\n",
       "\"name\":\"light\",\n",
       "\"panel_grid\":{\n",
       "\"blank\":true\n",
       "}\n",
       "}\n",
       "};\n",
       "           var plotContainer = document.getElementById(\"97wlhC\");\n",
       "           window.letsPlotCall(function() {{\n",
       "               LetsPlot.buildPlotFromProcessedSpecs(plotSpec, -1, -1, plotContainer);\n",
       "           }});\n",
       "       })();    \n",
       "   </script>"
      ]
     },
     "execution_count": 9,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "p + geomLabel(size = 9, alpha = 0.5, lineheight = 2) { label = \"label\"; hjust = \"hjust\"; vjust = \"vjust\" }"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "renewable-lying",
   "metadata": {},
   "outputs": [],
   "source": []
  },
  {
   "cell_type": "code",
   "execution_count": 10,
   "id": "composite-charleston",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/html": [
       "   <div id=\"ArweHS\"></div>\n",
       "   <script type=\"text/javascript\" data-lets-plot-script=\"plot\">\n",
       "       (function() {\n",
       "           var plotSpec={\n",
       "\"mapping\":{\n",
       "\"x\":\"x\",\n",
       "\"y\":\"y\"\n",
       "},\n",
       "\"data\":{\n",
       "\"x\":[\"a\",\"b\",\"c\"],\n",
       "\"y\":[1.2,3.4,2.5]\n",
       "},\n",
       "\"ggsize\":{\n",
       "\"width\":500.0,\n",
       "\"height\":300.0\n",
       "},\n",
       "\"kind\":\"plot\",\n",
       "\"scales\":[],\n",
       "\"layers\":[{\n",
       "\"mapping\":{\n",
       "},\n",
       "\"stat\":\"identity\",\n",
       "\"size\":4.0,\n",
       "\"position\":\"identity\",\n",
       "\"geom\":\"point\",\n",
       "\"data\":{\n",
       "}\n",
       "},{\n",
       "\"mapping\":{\n",
       "\"label\":\"y\"\n",
       "},\n",
       "\"stat\":\"identity\",\n",
       "\"position\":\"identity\",\n",
       "\"geom\":\"text\",\n",
       "\"data\":{\n",
       "}\n",
       "}]\n",
       "};\n",
       "           var plotContainer = document.getElementById(\"ArweHS\");\n",
       "           window.letsPlotCall(function() {{\n",
       "               LetsPlot.buildPlotFromProcessedSpecs(plotSpec, -1, -1, plotContainer);\n",
       "           }});\n",
       "       })();    \n",
       "   </script>"
      ]
     },
     "execution_count": 10,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "// Adjust position by nudging a given offset\n",
    "\n",
    "val p2 = letsPlot(\n",
    "    data = mapOf(\n",
    "        \"x\" to listOf('a', 'b', 'c'), \"y\" to listOf(1.2, 3.4, 2.5)\n",
    "    )\n",
    ") {\n",
    "    x = \"x\"\n",
    "    y = \"y\"\n",
    "} + geomPoint(size = 4) + ggsize(500, 300)\n",
    "\n",
    "p2 + geomText() { label = \"y\" }\n"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 11,
   "id": "applied-collins",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/html": [
       "   <div id=\"V0GbVl\"></div>\n",
       "   <script type=\"text/javascript\" data-lets-plot-script=\"plot\">\n",
       "       (function() {\n",
       "           var plotSpec={\n",
       "\"mapping\":{\n",
       "\"x\":\"x\",\n",
       "\"y\":\"y\"\n",
       "},\n",
       "\"data\":{\n",
       "\"x\":[\"a\",\"b\",\"c\"],\n",
       "\"y\":[1.2,3.4,2.5]\n",
       "},\n",
       "\"ggsize\":{\n",
       "\"width\":500.0,\n",
       "\"height\":300.0\n",
       "},\n",
       "\"kind\":\"plot\",\n",
       "\"scales\":[],\n",
       "\"layers\":[{\n",
       "\"mapping\":{\n",
       "},\n",
       "\"stat\":\"identity\",\n",
       "\"size\":4.0,\n",
       "\"position\":\"identity\",\n",
       "\"geom\":\"point\",\n",
       "\"data\":{\n",
       "}\n",
       "},{\n",
       "\"mapping\":{\n",
       "\"label\":\"y\"\n",
       "},\n",
       "\"stat\":\"identity\",\n",
       "\"position\":{\n",
       "\"name\":\"nudge\",\n",
       "\"y\":0.2,\n",
       "\"kind\":\"pos\"\n",
       "},\n",
       "\"geom\":\"text\",\n",
       "\"data\":{\n",
       "}\n",
       "}]\n",
       "};\n",
       "           var plotContainer = document.getElementById(\"V0GbVl\");\n",
       "           window.letsPlotCall(function() {{\n",
       "               LetsPlot.buildPlotFromProcessedSpecs(plotSpec, -1, -1, plotContainer);\n",
       "           }});\n",
       "       })();    \n",
       "   </script>"
      ]
     },
     "execution_count": 11,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "// Move text - use 'positionNudge()'\n",
    "\n",
    "p2 + geomText(position = positionNudge(y = 0.2)) { label = \"y\" } "
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 12,
   "id": "incorrect-electric",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/html": [
       "   <div id=\"jO0RCq\"></div>\n",
       "   <script type=\"text/javascript\" data-lets-plot-script=\"plot\">\n",
       "       (function() {\n",
       "           var plotSpec={\n",
       "\"mapping\":{\n",
       "\"x\":\"x\",\n",
       "\"y\":\"y\"\n",
       "},\n",
       "\"data\":{\n",
       "\"x\":[\"a\",\"b\",\"c\"],\n",
       "\"y\":[1.2,3.4,2.5]\n",
       "},\n",
       "\"ggsize\":{\n",
       "\"width\":500.0,\n",
       "\"height\":300.0\n",
       "},\n",
       "\"kind\":\"plot\",\n",
       "\"scales\":[],\n",
       "\"layers\":[{\n",
       "\"mapping\":{\n",
       "},\n",
       "\"stat\":\"identity\",\n",
       "\"size\":4.0,\n",
       "\"position\":\"identity\",\n",
       "\"geom\":\"point\",\n",
       "\"data\":{\n",
       "}\n",
       "},{\n",
       "\"nudge_y\":0.2,\n",
       "\"mapping\":{\n",
       "\"label\":\"y\"\n",
       "},\n",
       "\"stat\":\"identity\",\n",
       "\"position\":{\n",
       "\"name\":\"nudge\",\n",
       "\"y\":0.2,\n",
       "\"kind\":\"pos\"\n",
       "},\n",
       "\"geom\":\"text\",\n",
       "\"data\":{\n",
       "}\n",
       "}]\n",
       "};\n",
       "           var plotContainer = document.getElementById(\"jO0RCq\");\n",
       "           window.letsPlotCall(function() {{\n",
       "               LetsPlot.buildPlotFromProcessedSpecs(plotSpec, -1, -1, plotContainer);\n",
       "           }});\n",
       "       })();    \n",
       "   </script>"
      ]
     },
     "execution_count": 12,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "// Same with 'nudgeY'\n",
    "\n",
    "p2 + geomText(nudgeY = 0.2) { label = \"y\" }"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "experienced-american",
   "metadata": {},
   "outputs": [],
   "source": []
  },
  {
   "cell_type": "code",
   "execution_count": 13,
   "id": "likely-joyce",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/html": [
       "   <div id=\"H3DpRs\"></div>\n",
       "   <script type=\"text/javascript\" data-lets-plot-script=\"plot\">\n",
       "       (function() {\n",
       "           var plotSpec={\n",
       "\"mapping\":{\n",
       "\"x\":\"x\",\n",
       "\"y\":\"y\"\n",
       "},\n",
       "\"data\":{\n",
       "\"x\":[1.0,1.0,2.0,2.0,1.5],\n",
       "\"y\":[1.0,2.0,1.0,2.0,1.5],\n",
       "\"text\":[\"bottom-left\",\"top-left\",\"bottom-right\",\"top-right\",\"center\"]\n",
       "},\n",
       "\"ggsize\":{\n",
       "\"width\":500.0,\n",
       "\"height\":300.0\n",
       "},\n",
       "\"kind\":\"plot\",\n",
       "\"scales\":[],\n",
       "\"layers\":[{\n",
       "\"mapping\":{\n",
       "},\n",
       "\"stat\":\"identity\",\n",
       "\"size\":4.0,\n",
       "\"position\":\"identity\",\n",
       "\"geom\":\"point\",\n",
       "\"data\":{\n",
       "}\n",
       "},{\n",
       "\"mapping\":{\n",
       "\"label\":\"text\"\n",
       "},\n",
       "\"stat\":\"identity\",\n",
       "\"size\":8.0,\n",
       "\"position\":\"identity\",\n",
       "\"geom\":\"text\",\n",
       "\"data\":{\n",
       "}\n",
       "}]\n",
       "};\n",
       "           var plotContainer = document.getElementById(\"H3DpRs\");\n",
       "           window.letsPlotCall(function() {{\n",
       "               LetsPlot.buildPlotFromProcessedSpecs(plotSpec, -1, -1, plotContainer);\n",
       "           }});\n",
       "       })();    \n",
       "   </script>"
      ]
     },
     "execution_count": 13,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "// Justification: 'inward' and 'outward'\n",
    "\n",
    "val data2 = mapOf(\n",
    "   \"x\" to listOf(1, 1, 2, 2, 1.5),\n",
    "   \"y\" to listOf(1, 2, 1, 2, 1.5),\n",
    "   \"text\" to listOf(\"bottom-left\", \"top-left\", \"bottom-right\", \"top-right\", \"center\")\n",
    ")\n",
    "\n",
    "val p3 = letsPlot(data2) { x = \"x\"; y = \"y\" } + geomPoint(size = 4) + ggsize(500, 300)\n",
    "\n",
    "p3 + geomText(size = 8) { label = \"text\" }"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 14,
   "id": "traditional-brush",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/html": [
       "   <div id=\"rt3u8z\"></div>\n",
       "   <script type=\"text/javascript\" data-lets-plot-script=\"plot\">\n",
       "       (function() {\n",
       "           var plotSpec={\n",
       "\"mapping\":{\n",
       "\"x\":\"x\",\n",
       "\"y\":\"y\"\n",
       "},\n",
       "\"data\":{\n",
       "\"x\":[1.0,1.0,2.0,2.0,1.5],\n",
       "\"y\":[1.0,2.0,1.0,2.0,1.5],\n",
       "\"text\":[\"bottom-left\",\"top-left\",\"bottom-right\",\"top-right\",\"center\"]\n",
       "},\n",
       "\"ggsize\":{\n",
       "\"width\":500.0,\n",
       "\"height\":300.0\n",
       "},\n",
       "\"kind\":\"plot\",\n",
       "\"scales\":[],\n",
       "\"layers\":[{\n",
       "\"mapping\":{\n",
       "},\n",
       "\"stat\":\"identity\",\n",
       "\"size\":4.0,\n",
       "\"position\":\"identity\",\n",
       "\"geom\":\"point\",\n",
       "\"data\":{\n",
       "}\n",
       "},{\n",
       "\"mapping\":{\n",
       "\"label\":\"text\"\n",
       "},\n",
       "\"stat\":\"identity\",\n",
       "\"vjust\":\"inward\",\n",
       "\"size\":8.0,\n",
       "\"position\":\"identity\",\n",
       "\"geom\":\"text\",\n",
       "\"hjust\":\"inward\",\n",
       "\"data\":{\n",
       "}\n",
       "}]\n",
       "};\n",
       "           var plotContainer = document.getElementById(\"rt3u8z\");\n",
       "           window.letsPlotCall(function() {{\n",
       "               LetsPlot.buildPlotFromProcessedSpecs(plotSpec, -1, -1, plotContainer);\n",
       "           }});\n",
       "       })();    \n",
       "   </script>"
      ]
     },
     "execution_count": 14,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "p3 + geomText(size = 8, hjust = \"inward\", vjust = \"inward\") { label = \"text\" }"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 15,
   "id": "alike-membership",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/html": [
       "   <div id=\"1mgYb4\"></div>\n",
       "   <script type=\"text/javascript\" data-lets-plot-script=\"plot\">\n",
       "       (function() {\n",
       "           var plotSpec={\n",
       "\"mapping\":{\n",
       "\"x\":\"x\",\n",
       "\"y\":\"y\"\n",
       "},\n",
       "\"data\":{\n",
       "\"x\":[1.0,1.0,2.0,2.0,1.5],\n",
       "\"y\":[1.0,2.0,1.0,2.0,1.5],\n",
       "\"text\":[\"bottom-left\",\"top-left\",\"bottom-right\",\"top-right\",\"center\"]\n",
       "},\n",
       "\"ggsize\":{\n",
       "\"width\":500.0,\n",
       "\"height\":300.0\n",
       "},\n",
       "\"kind\":\"plot\",\n",
       "\"scales\":[],\n",
       "\"layers\":[{\n",
       "\"mapping\":{\n",
       "},\n",
       "\"stat\":\"identity\",\n",
       "\"size\":4.0,\n",
       "\"position\":\"identity\",\n",
       "\"geom\":\"point\",\n",
       "\"data\":{\n",
       "}\n",
       "},{\n",
       "\"mapping\":{\n",
       "\"label\":\"text\"\n",
       "},\n",
       "\"stat\":\"identity\",\n",
       "\"vjust\":\"outward\",\n",
       "\"size\":8.0,\n",
       "\"position\":\"identity\",\n",
       "\"geom\":\"text\",\n",
       "\"hjust\":\"outward\",\n",
       "\"data\":{\n",
       "}\n",
       "}]\n",
       "};\n",
       "           var plotContainer = document.getElementById(\"1mgYb4\");\n",
       "           window.letsPlotCall(function() {{\n",
       "               LetsPlot.buildPlotFromProcessedSpecs(plotSpec, -1, -1, plotContainer);\n",
       "           }});\n",
       "       })();    \n",
       "   </script>"
      ]
     },
     "execution_count": 15,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "p3 + geomText(size = 8, hjust = \"outward\", vjust = \"outward\") { label = \"text\" }"
   ]
  }
 ],
 "metadata": {
  "kernelspec": {
   "display_name": "Kotlin",
   "language": "kotlin",
   "name": "kotlin"
  },
  "language_info": {
   "codemirror_mode": "text/x-kotlin",
   "file_extension": ".kt",
   "mimetype": "text/x-kotlin",
   "name": "kotlin",
   "nbconvert_exporter": "",
   "pygments_lexer": "kotlin",
   "version": "1.7.20-dev-1299"
  }
 },
 "nbformat": 4,
 "nbformat_minor": 5
}
